package com.yami.shop.admin;

import cn.hutool.http.HttpUtil;
import com.yami.shop.payment.WeChatPayment;
import com.yami.shop.payment.dto.GetJsapiServiceDto;
import com.yami.shop.payment.dto.PayParamDto;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Map;

@SpringBootTest
@RunWith(SpringRunner.class)
public class SpringBootTest01 {
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private WeChatPayment weChatPayment;

    @Test
    public void findOne() throws Exception {
        System.out.println(System.getProperty("user.dir"));
    }

    @Test
    public void findOne1() throws Exception {
        String encode = passwordEncoder.encode("123456");
        System.out.println(encode);
    }

    @Test
    public void findOne333() throws Exception {
        GetJsapiServiceDto getJsapiServiceDto = new GetJsapiServiceDto();
        getJsapiServiceDto.setWechatpayMchid(WeChatPayment.wechatpayMchid);
        getJsapiServiceDto.setWechatpayMchserialno(WeChatPayment.wechatpayMchserialno);
        getJsapiServiceDto.setWechatpayPrivatekey(WeChatPayment.wechatpayPrivatekey);
        getJsapiServiceDto.setWechatpayApiv3key(WeChatPayment.wechatpayApiv3key);

        getJsapiServiceDto.setWechatpayAppid(WeChatPayment.wechatpayAppid);
        getJsapiServiceDto.setWechatpayAppsecret(WeChatPayment.wechatpayAppsecret);

        PayParamDto payParamDto=new PayParamDto();
        payParamDto.setMerchantId("1679492339");
        payParamDto.setAppid("wx3f48e4d51328dc99");
        payParamDto.setAmount(new BigDecimal("1"));
        payParamDto.setOpenid("otrMZ7VYtavcr4l6-uxMxElQt8uU");
        payParamDto.setDescription("购买");
        payParamDto.setOutTradeNo("123555");
        payParamDto.setParam(null);

        String pay = weChatPayment.pay(payParamDto,getJsapiServiceDto);
        System.out.println(pay);
    }

    @Test
    public void findOne444() throws Exception {
        String openId = weChatPayment.getOpenId("0e1i5zll2N58Vd4gZSll2j7FEK0i5zlh");
        System.out.println(openId);
    }


    public static void main(String[] args) throws IOException {

        /*for (int i=0;i<100;i++){
            String deliveryJson = HttpUtil.get("http://www.kuaidi100.com/query?type=yuantong&postid=YT3596143820365&id=11");
            System.out.println(deliveryJson);
        }*/

        OkHttpClient client = new OkHttpClient();

        String url = "http://www.kuaidi100.com/query?type=yuantong&postid=YT3596143820365&id=11";
        Request request = new Request.Builder()
                .url(url)
                .build();

        for (int i=0;i<100;i++){
            Response response = client.newCall(request).execute();
            System.out.println(response.body().string());
        }
    }
}
